package mmpathgen.util;

import java.io.File;
import java.util.List;

import soot.EntryPoints;
import soot.Scene;
import soot.SootClass;

public class ClassLoader {

	public static void loadClass(String[] pkgList, String[][] clsList,
			String mainClassName) {
		// set auxiliary application class
		for (int i = 0; i < pkgList.length; i++) {
			for (int j = 0; j < clsList[i].length; j++) {
				// System.out.println("i: " + i);
				// System.out.println("j: " + j);
				// System.out.println(pkgList[i] + clsList[i][j]);
				SootClass c = Scene.v().loadClassAndSupport(
						pkgList[i] + "." + clsList[i][j]);
				c.setApplicationClass();
			}
		}

		// set main application class
		SootClass mainClass = Scene.v().loadClassAndSupport(mainClassName);
		mainClass.setApplicationClass();
		Scene.v().setMainClass(mainClass);
		
		soot.Scene.v().loadNecessaryClasses();
		soot.Scene.v().setEntryPoints(EntryPoints.v().all());
	}

	public static void loadClass(File path, String mainClassName) {
//		// get the class names automatically
//		List<String> clsNames = JavaClassNameExtractor
//				.extractJavaClassNames(path);
//
//		// set auxiliary application class
//		for (String clsName : clsNames) {
//			SootClass c = Scene.v().loadClassAndSupport(clsName);
//			c.setApplicationClass();
//		}
		
		// set auxiliary application class
		SootClass c = Scene.v().loadClassAndSupport(mainClassName);
		c.setApplicationClass();
		
		// set main application class
		SootClass mainClass = Scene.v().loadClassAndSupport(mainClassName);
		mainClass.setApplicationClass();
		Scene.v().setMainClass(mainClass);
		
		soot.Scene.v().loadNecessaryClasses();
		soot.Scene.v().setEntryPoints(EntryPoints.v().all());
	}

}
